<?php namespace dmq;

/**
 * Super class that all the Models inherits from.
 * @abstract
 */
abstract class Model
{
	protected $db;	// (Database).

	/**
    * The constructor and should never be overridden.
    * @final
    * @param $useDb database object
    */
	final public function __construct( $useDb )
	{
		// sets the database object to false
		$this->db = false;

		if ( $useDb )
		{
			require_once Settings::DMQ_PATH . 'Database.php';
			$this->db = new Database();
			// open the new databaseconnection.
			$this->db->open();
		}
	}
	
	/**
    * The destructor and should never be overridden.
    * @final
    * The destructor will be called to exit the application and close the databaseconnection.
    */
	final public function __destruct()
	{
		if ( $this->db )
		{
			// close databaseconnection
			$this->db->close();
		}
	}
}
